package t1003;


import java.util.Scanner;

/**
 * 姓名： 张东升
 * 日期: 2025年03月2025/3/10日
 * https://gitee.com/miqima/data-structure-homework.git
 * 5 4 24 2 5 3
 * 6 78 36 34 24 64 43
 */
public class Main {


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // 创建数组A
        int A_Length = sc.nextInt();
        int[] array1 = createArray(sc, A_Length);

        // 创建数组B
        int B_Length = sc.nextInt();
        int[] array2 = createArray(sc, B_Length);

        // 开始合并两个数组
        int C_Length = A_Length + B_Length;
        int[] merged = merge(array1, array2, A_Length, B_Length, C_Length);

        // 输出数组
        dispList(array1, A_Length);
        dispList(array2, B_Length);
        dispList(merged, C_Length);
    }


    /**
     * 合并来两个数组
     *
     * @param a      数组a
     * @param b      数组b
     * @param length 数组长度
     * @return 合并后的数组
     */
    public static int[] merge(int[] a, int[] b, int al, int bl, int length) {
        int[] merged = new int[length];
        for (int i = 0; i < al; i++) {
            merged[i] = a[i];
        }

        for (int i = 0; i < bl; i++) {
            merged[al++] = b[i];
        }
        return merged;
    }


    /**
     * 数组排序
     *
     * @param length 数组长度
     * @param array  数组
     */
    public static void sortList(int[] array, int length) {
        for (int i = 0; i < length; i++) {
            for (int j = i + 1; j < length; j++) {
                if (array[i] > array[j]) {
                    int temp = array[i];
                    array[i] = array[j];
                    array[j] = temp;
                }
            }
        }
    }


    /**
     * 创建数组
     *
     * @param sc 键盘输入
     * @return 新数组
     */
    public static int[] createArray(Scanner sc, int length) {
        // 创建数组
        int[] num = new int[length];
        for (int i = 0; i < length; i++) {
            num[i] = sc.nextInt();
        }
        return num;
    }


    /**
     * 输出数组
     *
     * @param num 数组
     * @param n   数组长度
     */
    public static void dispList(int[] num, int n) {
        sortList(num, n);
        System.out.println("The length:" + n);
        System.out.println("The elements:");
        for (int i = 0; i < n; i++) {
            System.out.printf(num[i] + " ");
        }
        System.out.printf("\n");
    }
}
